﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using XTYAPI.PLC;
using static System.Windows.Forms.AxHost;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using static XTYAPI.PLC.BitRun;

namespace XTYAPIDemo
{
    public partial class FrmDemo : Form
    {
        public FrmDemo()
        {
            InitializeComponent();
        }
        PLCDemo plc = new PLCDemo();

        private void button1_Click(object sender, EventArgs e)
        {
            byte b = plc.ENCO.ENCO_Byte(new bool[8] { true, true, false, false, false, false, false, false });
        }

        private void button2_MouseDown(object sender, MouseEventArgs e)
        {
            plc.ALTPstate = true;
        }

        private void button2_MouseUp(object sender, MouseEventArgs e)
        {
            plc.ALTPstate = false;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            textBox1.Text = "guijokf";
            plc.ALTP.InPut = plc.ALTPstate;
            label1.Text = plc.ALTP.OutPut.ToString();
            plc.SR.S = plc.RS.S = plc.Set;
            plc.SR.R = plc.RS.R = plc.Rst;
            label5.Text = plc.SR.OutSR.ToString();
            label6.Text = plc.RS.OutSR.ToString();
            #region 数字计算集合

            #endregion
        }
        #region 置位复位优先
        private void button3_MouseDown(object sender, MouseEventArgs e)
        {
            plc.Set = true;
        }
        private void button3_MouseUp(object sender, MouseEventArgs e)
        {
            plc.Set = false;
        }
        private void button4_MouseDown(object sender, MouseEventArgs e)
        {
            plc.Rst = true;
        }
        private void button4_MouseUp(object sender, MouseEventArgs e)
        {
            plc.Rst = false;
        }

        private void button5_MouseDown(object sender, MouseEventArgs e)
        {
            plc.Set = true;
            plc.Rst = true;
        }

        private void button5_MouseUp(object sender, MouseEventArgs e)
        {
            plc.Set = false;
            plc.Rst = false;
        }
        private void button6_MouseDown(object sender, MouseEventArgs e)
        {
            plc.Set = true;
            plc.Rst = true;
        }
        private void button6_MouseUp(object sender, MouseEventArgs e)
        {
            plc.Set = false;
            plc.Rst = false;
        }

        #endregion

        #region 与或
        private void button7_Click(object sender, EventArgs e)
        {
            label7.Text = plc.CalAnd().ToString();
        }

        private void button8_Click(object sender, EventArgs e)
        {
            label9.Text = plc.CalOR().ToString();
        }
        #endregion

        #region 数字集合计算
     
        bool bitcalTest = false;

        private void button9_Click(object sender, EventArgs e)
        {
            plc.BitRunAdd();//添加变量及逻辑
           
        }
        private void button10_Click(object sender, EventArgs e)
        {
            timer2.Enabled = true;
        }
        private void timer2_Tick(object sender, EventArgs e)
        {
            bitcalTest = !bitcalTest;
            plc.BitRun.ValuePairs["启动"] = bitcalTest;
            plc.BitRun.ValuePairs["停止"] = true;
            plc.BitRun.Run();
            timer2.Enabled = false;
            label11.Text = plc.BitRun.ValuePairs["输出"].ToString();

        }

        #endregion


    }
}
